#include<stdio.h>
#include<math.h> 
int main()
{
	int a,b,temp;
	while( (scanf("%d",&a))!=EOF )
	{
		scanf("%d",&b);
		temp=b%4;
		a%=10;
		//printf("%d %d\n",a,temp);
		if(temp==0)
			temp=4;
		a=pow(a,temp);
		printf("%d\n",a%10);
	}
	return 0;
}
